package com.example.votemanage.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.votemanage.entity.VoteSubject;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author liufangzhou
 * @since 2024-06-06
 */
public interface VoteSubjectMapper extends BaseMapper<VoteSubject> {

    @Select("select * from VOTE_SUBJECT order by vs_id")
    @Results(id = "subject_Map",value = {
            @Result(property = "vsId",column = "vs_Id"),
            @Result(property = "options",column = "vs_Id",many=@Many(select = "com.example.votemanage.mapper.VoteOptionMapper.findOptionByVsId")),
            @Result(property = "items",column = "vs_Id",many=@Many(select = "com.example.votemanage.mapper.VoteItemMapper.findItemByVsId"))
    })
    public IPage<VoteSubject> findAll(Page<VoteSubject> page);

    @Select("select * from VOTE_SUBJECT where vs_id=#{vsid}")
    @ResultMap(value="subject_Map")
    public VoteSubject findSubjectByVsId(int vsid);
}
